from multiprocessing import Pool, Value, Manager

total = 0


def f(args):
    (total_val, lock,) = args
    for _ in range(1000):
        global total
        total += 1
        total_val.value += 1  # 1000~2000
        # with lock:
        #     total_val.value += 1 # 5000


if __name__ == '__main__':
    with Manager() as manager:
        total_val = manager.Value('d', 0)
        lock = manager.Lock()
        with Pool(5) as pool:
            pool.map(f, [(total_val, lock,) for i in range(5)])
        print(total_val.value)
    print(total)
